package com.credithc.customers.base.ro;

import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.utils.CustomerUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

/**
 * @description: 统一登录忘记/修改密码
 * @author: fby
 * @date: 2019/7/8 15:47
 * @param: null
 * @return:
 */
@Data
public class UnifyPwdRo extends CustomerBaseRo {

    private String phone;

    private String password;

    private String confirmPassword;

    private String sourceType;


    public static void checkBaseParam(UnifyPwdRo ro) {
        if (StringUtils.isBlank(ro.getRequestNo())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请求流水号不能为空");
        }
        if (StringUtils.isBlank(ro.getPhone())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "手机号不能为空");
        }
        if (StringUtils.isBlank(ro.getPassword())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请填写新密码");
        }
        if (StringUtils.isBlank(ro.getConfirmPassword())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请填写确认密码");
        }
        if (!ro.getPassword().equals(ro.getConfirmPassword())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "确认密码与新密码不一致，请重新填写");
        }
        CustomerUtils.checkPassword(ro.getPassword());
    }
}
